package com.bsc.rtc.lib.libraries.MyViewDemo.wj;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class WJTextView extends View {
    private int srceenWidth;
    private int screenHeight;

    Path path;
    Paint paint;
    public WJTextView(Context context) {
        super(context);
        init();
    }

    public WJTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public WJTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        path = new Path();
        paint=new Paint();
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(3f);
        //抗锯齿
        paint.setAntiAlias(true);
        //防抖动
        paint.setDither(true);
        //设置画笔未实心
        paint.setStyle(Paint.Style.STROKE);
    }

    private void changePath() {
        int currentX = (srceenWidth / 2) - 50;
        int currentY = screenHeight / 2;
        path.moveTo(currentX, currentY);
        path.lineTo(currentX + 50, currentY + 50);
        path.lineTo(currentX + 80 , currentY);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        srceenWidth = getMeasuredWidth();
        screenHeight = getMeasuredHeight();
        changePath();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawWJ(canvas);
    }

    private void drawWJ(Canvas canvas) {
        canvas.drawPath(path,paint);
    }

    private void moveToCenter(Canvas canvas) {

    }
}
